package com.ac.cv.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel;

public class EnhancedImage extends Composite {

	private Image image;
	
	private Image thumbnail;
	
	public EnhancedImage(final Image image, final Image thumbnail){
		this.image = image;
		this.thumbnail = thumbnail;
		final PopupPanel imagePopup = new PopupPanel(true);
		thumbnail.addStyleName("selectable");
		image.addStyleName("selectable");
		
	    imagePopup.setAnimationEnabled(true);
	    imagePopup.setWidget(this.image);
	    this.image.addClickHandler(new ClickHandler() {
	      public void onClick(ClickEvent event) {
	        imagePopup.hide();
	      }
	    });

	    this.thumbnail.addClickHandler(new ClickHandler() {
	      public void onClick(ClickEvent event) {
	    	 if(!imagePopup.isShowing()){
	    		 imagePopup.setPopupPosition(thumbnail.getAbsoluteLeft() + 20, thumbnail.getAbsoluteTop() + 20);
	    		 imagePopup.show();	    		 
	    	 } else {
	    		 imagePopup.hide();
	    	 }
	      }
	    });	    
		initWidget(this.thumbnail);		
	}	
}
